package com.sxbang.friday.controller;


import com.sxbang.friday.base.result.PageTableRequest;
import com.sxbang.friday.base.result.Results;
import com.sxbang.friday.model.SysRole;
import com.sxbang.friday.model.SysUser;
import com.sxbang.friday.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/role")
@Slf4j
public class RoleController {
    @Autowired
    private RoleService roleService;
    @RequestMapping("/all")
    @ResponseBody
    public Results<SysRole> getAll(){
        log.info("nihao");
        Results<SysRole> sysRoleResults = roleService.getAllRoles();
        log.info("nihao:;;;;;;;;;;;;;;"+sysRoleResults);
        return sysRoleResults;
    }
    @RequestMapping("/list")
    @ResponseBody//url中会默认的传入page和limit
    public Results<SysRole> user(PageTableRequest pageTableRequest) {//返回一个Result<SysUser>//还需要定义一个类计算当前页和起始页和需要返回的页数的类PageTableRequest
        pageTableRequest.countOffset();//如如果的当前页没有指定，获取显示的行数没有指定，行数为0
        return roleService.selectRole(pageTableRequest.getOffset(), pageTableRequest.getLimit());//出入参数起始位置，和查
    }
    @GetMapping("/add")
    public String userAdd(Model model) {
        model.addAttribute(new SysRole());//初始化列表
        return "role/role-add";
    }
    @RequestMapping("/findUserByFuzzyUsername")
    @ResponseBody//url中会默认的传入page和limit
    public Results<SysRole> findUserByFuzzyUsername(PageTableRequest pageTableRequest,String name) {//返回一个Result<SysUser>//还需要定义一个类计算当前页和起始页和需要返回的页数的类PageTableRequest
        System.out.println(/*pageTableRequest+*/"---------------"+name+"------");
        pageTableRequest.countOffset();//如如果的当前页没有指定，获取显示的行数没有指定，行数为0
        return roleService.getUserByFuzzyUsername(name,pageTableRequest.getOffset(), pageTableRequest.getLimit());//出入参数起始位置，和查
    }

}
